import { PassportModule } from '@nestjs/passport';
import { config } from 'src/config';
import { Module } from '@nestjs/common';
import { MulterModule } from '@nestjs/platform-express';
import { diskStorage } from 'multer';
import { UploadController } from './upload.controller';
import { UploadService } from './upload.service';
import * as path from 'path';
import { uid } from 'uid';

@Module({
  imports: [
    MulterModule.register({
      storage: diskStorage({
        destination: path.join(__dirname, '../../' + config.uploadPath),
        filename(req, file, cb) {
          cb(
            null,
            uid(32) + '-' + Date.now() + path.extname(file.originalname),
          );
        },
      }),
    }),
    PassportModule.register({ defaultStrategy: 'jwt' }),
  ],
  controllers: [UploadController],
  providers: [UploadService],
})
export class UploadModule {}
